from bs4 import BeautifulSoup
# !/usr/bin/env python
# encoding: utf-8

#
import sys

reload(sys)
sys.setdefaultencoding('utf8')
f = open("./www/tpl/img-test.html", "r")
fls = f.readlines()
f.close()
fls = [l.strip() for l in fls]

fs = u" ".join(fls)
print fs

print "---"
soup = BeautifulSoup(fs, "html.parser")
img = soup.findAll("img")
cdn = "https://www.yirendai.com"
for temp_img in img:
    if (temp_img.has_attr('src') and not temp_img['src'].startswith('http://') and not temp_img['src'].startswith(
            'https://')):
        src = temp_img['src']
        src = src.replace('../img/', "/img/")
        temp_img['src'] = cdn + src

fs = str(soup)
print fs
# deploy_html_file = open('deploy', "w")
# deploy_html_file.write(str(soup))
# deploy_html_file.close()
